package com.gywj.race.service;

import com.gywj.race.config.exception.BaseException;
import com.gywj.race.entity.Employees;
import com.gywj.race.entity.EmployeesExample;
import com.gywj.race.mapper.EmployeesMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Collections;
import java.util.List;

/**
 * The type Employee service.
 */
@Service
public class EmployeeService {
    @Resource
    private EmployeesMapper employeesMapper;

    /**
     * Login employees.
     *
     * @param userName the user name
     * @param password the password
     * @return the employees
     */
    public Employees login(String userName, String password) {
        EmployeesExample employeesExample = new EmployeesExample();
        employeesExample.createCriteria().andLoginNameEqualTo(userName);
        List<Employees> employees = employeesMapper.selectByExample(employeesExample);
        if (CollectionUtils.isEmpty(employees)) {
            throw new BaseException("用户名不存在");
        }
        Employees employee = employees.get(0);
        if (!employee.getPassword().equals(password)) {
            throw new BaseException("密码不正确");
        }
        return employee;

    }
}
